package org.example.Day6.JDK8;

import org.example.Day4.Student;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

public class StreamTest2 {
    /**
     * 常见Stream流中间方法
     * @param args
     */
    public static void main(String[] args){
        List<Double> scores = new ArrayList<>();
        Collections.addAll(scores, 88.5, 100.0, 60.0, 99.0, 9.5, 99.6, 25.0);

        //找出大于60分的成绩升序后输出
        scores.stream().filter(s -> s >= 60).sorted().forEach(s->System.out.println(s));

        List<Student> students = new ArrayList<>();
        Student s1 = new Student("蜘蛛精",  172.5,26);
        Student s2 = new Student("蜘蛛精",  172.5,26);
        Student s3 = new Student("紫霞",  167.6,23);
        Student s4 = new Student("⽩晶晶",  169.0,25);
        Student s5 = new Student("⽜魔王",  183.3,35);
        Student s6 = new Student("⽜夫⼈",  168.5,34);
        Collections.addAll(students, s1, s2, s3, s4, s5, s6);
        //返回23岁到30岁之间并升序排序的
        students.stream().filter(s->s.getAge() >=23 && s.getAge()<=30)
                .sorted((o1,o2) ->o2.getAge()-o1.getAge()).forEach(s->System.out.println(s));
        //返回3个身高最高的并输出
        students.stream().sorted((o1,o2)->Double.compare(o2.getHeight(),o1.getHeight()))
                .limit(3).forEach(System.out::println);
        System.out.println("-----------------------------------------------");
        //取出身高倒数2名的同学
        students.stream().sorted((o1,o2)->Double.compare(o2.getHeight(),o1.getHeight()))
                .skip(students.size()-2).forEach(System.out::println);

        //找出身高超过168的学生叫什么，去掉重复名字输出
        students.stream().filter(s->s.getHeight() > 168).map(Student::getName)
                .distinct().forEach(System.out::println);
        //distinct去重 自定义类型对象(希望内容一样就认为重复,重写hashcode,equals)
        students.stream().filter(s->s.getHeight()>168).distinct().forEach(System.out::println);

            Stream<String> st1 = Stream.of("张三", "李四");
            Stream<String> st2 = Stream.of("张三2", "李四2", "王五");
            Stream<String> allSt = Stream.concat(st1, st2);
            allSt.forEach(System.out::println);

    }
}
